<?php
/**
 * Created by PhpStorm.
 * User: Inhere
 * Date: 15-4-1
 * Time: 上午10:08
 * Used:
 * file: ConsoleApplication.php
 */

namespace ulue\cli\io;

use Windwalker\IO\Cli\Input;
// use Windwalker\IO\Cli\Output\CliOutput;

class CliInput extends Input\CliInput
{
    public $rawArgs = [];

///////////////////////////////////////// raw params /////////////////////////////////////////

    /**
     * @override
     * @param  mixed $source
     */
    protected function prepareSource($source = null)
    {
        // Get the command line options
        parent::prepareSource();

        $argv = $_SERVER['argv'];

        array_shift($argv);

        $this->rawArgs = $argv;
    }

    /**
     * @return array
     */
    public function getRawArgs()
    {
        return $this->rawArgs;
    }

    /**
     * @param array $args
     * @return $this
     */
    public function setRawArgs(array $args)
    {
        $this->rawArgs = $args;

        return $this;
    }

    /**
     * @param $key
     * @param null $default
     * @return null
     */
    public function getRawArg($key, $default = null)
    {
        return isset($this->rawArgs[$key]) ? $this->rawArgs[$key] : $default;
    }

    /**
     * @param $key
     * @param $value
     * @return $this
     */
    public function setRawArg($key, $value)
    {
        $this->rawArgs[$key] = $value;

        return $this;
    }

    /**
     * @return bool
     */
    public function rawExists($key)
    {
        return isset($this->rawArgs[$key]);
    }

    /**
     * @return bool
     */
    public function rawValExists($name)
    {
        return in_array( $name, $this->rawArgs );
    }
}